<template>
  <div class="order-list">
    <h1>订单列表</h1>
    <el-table :data="orders" border>
      <el-table-column prop="id" label="订单号" />
      <el-table-column prop="status" label="状态" />
      <el-table-column prop="createdAt" label="创建时间" />
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="viewDetail(scope.row.id)">查看详情</el-button>
          <el-button type="danger" @click="cancelOrder(scope.row.id)">取消订单</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getOrderList, cancelOrder } from '@/api/order';

export default {
  data() {
    return {
      orders: [],
    };
  },
  methods: {
    async fetchOrders() {
      console.log("123")
      const response = await getOrderList({ page: 1, pageSize: 10 });
      this.orders = response.data.orders;
    },
    viewDetail(orderNo) {
      this.$router.push({ path: `/orders/${orderNo}` });
    },
    async cancelOrder(orderNo) {
      await cancelOrder(orderNo);
      this.fetchOrders(); // 刷新订单列表
    },
  },
  mounted() {
    this.fetchOrders();
  },
};
</script>

<style scoped>
.order-list {
  padding: 20px;
}
</style> 